<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/set_pack_new.css">
<script src="__PUBLIC__js/circle.js"></script>
<style type="text/css">
.footer{
  display: none;
}
</style>
</block>
    
   <block name="main">
       <div class="container">
        <div class="content">
          <ul>
          <foreach name="packet_list.scheme" item="v">
            <li>
              <div class="set_red">
                <div class="title clearfix">
                  <div class="title_left">
                    <h4>{$v.scheme}</h4>
                  </div>
                  <div class="title_right">
                    <p>设置规则</p>
                  </div>
                </div>
                <div class="money">
                  <div class="pupil_bag">
                    <img src="__PUBLIC__images/pupil-bag.png" height="34" width="26">
                    <span>徒弟红包</span>
                  </div>
                  <div class="pupil_set">
                    <!-- setAll属性为总金额 -->
                    <input type="text" oninput="pack_match(this)" attr="{$v[p_user_award]+$v[p_push_award]}" placeholder="{$v.p_user_award}" value="{$v.p_user_award}" setAll="{$v[p_user_award]+$v[p_push_award]}"" tacit='{$v.p_user_award}' >
                    <span>元</span>
                  </div>
                  <div class="master_mon">
                    <p>师父红包<span>{$v.p_push_award}</span>元</p>
                  </div>
                  <div class="invest_detail">
                    <ul>
                      <li>
                        <h3>{$v.yields}%</h3>
                        <p>往期年化</p>
                      </li>
                      <li>
                        <h4>{$v.deadline}{$info['deadline_unit']?"天":'月'}</h4>
                        <p>投资期限</p>
                      </li>
                      <li>
                        <h4>{$v.start_amount}元</h4>
                        <p>起投金额</p>
                      </li>
                    </ul>
                  </div>
                  <div class="pack_red"  attr="{$v.id}">
                    包红包
                  </div>
                </div>
              </div>
            </li>
          </foreach> 

          </ul>
        </div>
      </div>
      <div class="set_rules">
        <div class="rules_detail">
          <h4>设置规则</h4>
          <p>1、红包金额可在允许区间内任意设置。</p>
          <p>2、最低设置金额为1元。</p>  
          <p>3、设置成功并分享给徒弟投资之后，徒弟将收到您设置的现金红包。</p>
          <div class="get_rules">
            知道了
          </div>
        </div>
      </div>
      <div class="set_pack_next">
        <div class="next_detail">
          <div class="next_background"></div>
          <div class="set_pack_mon">
            <p class="pupil_get">徒弟投资之后将收到600元红包，</p>
            <p class="master_get">您可以获得128元红包</p>
          </div>
          <div class="set_pack_btn">
            <div class="set_pack_return">继续设置红包</div>
            <div class="set_pack_sure" onclick=" location.href='/Home/Recommend/m_marketing/recommend_id/{$_SESSION[user][id]}/p_id/{$_GET[platform_id]}/s/{$v.id}'">确认分享该投资红包</div>
          </div>
        </div>
      </div>


          </block>
<block name="js">
      <script type="text/javascript">
  $('.title_right').click(function() {
          $('.set_rules').css('display','block')
        });
        $('.set_rules').click(function() {
          $('.set_rules').css('display','none')
        });
        $('.get_rules').click(function() {
          $('.set_rules').css('display','none')
        });
        function pack_match(obj){
        obj.value=obj.value.replace(/[^\d]/g,'');
        obj.value=obj.value.substr(0,3);
        var count =  parseInt($(obj).attr('setAll'));
        var td_pack =  parseInt($(obj).val())
        var master_pack = parseInt(count-td_pack)
        if(isNaN(master_pack)){
          master_pack=0
        };
        $(obj).parent('div').next('.master_mon').find('span').text(master_pack)
      }
      $('.pupil_set input').focus(function() {
        $(this).val('');console.log($(this).val(''))
      });
      $('.pupil_set input').keyup(function() {        
        var count =  parseInt($(this).attr('setAll'));
        if($(this).val() > count){
          layer.open({
                content: '最高只能输入'+count+'元！'
                ,skin: 'msg'
                ,time: 2.5//2秒后自动关闭
              });
          $(this).parent('div').next('.master_mon').find('span').text(0)
          $(this).val(count);
        }
      });
        $('.pack_red').each(function(index,el){
          $(el).click(function(){
            var pupil = $(el).parent('div').children('.pupil_set').children('input').val();
            var master = $(el).parent('div').children('.master_mon').children('p').children('span').text();
            var scheme_id =$(el).attr('attr');
            var postdata = {scheme_id:scheme_id,user_award:pupil,push_award:master}
            if(pupil>=1){
                 $.post('/Home/Circle/set_pack/platform_id/{$_GET[platform_id]}',postdata,function(res){
                  if(res.err==0){
                      $('.pupil_get').text('徒弟投资之后将收到'+pupil+'元红包');
                      $('.master_get').text('您可以获得'+master+'元红包')
                      $('.set_pack_next').css('display','block');
                      var attr_id = $(el).attr('attr');
                      $('.set_pack_sure').attr('onclick',"location.href='/Home/Recommend/m_marketing/recommend_id/{$_SESSION[user][id]}/p_id/{$_GET[platform_id]}/s/"+attr_id+"'");

                  }else{
                     layer.open({
                        content: res.msg
                        ,skin: 'msg'
                        ,time: 2 //2秒后自动关闭
                      });
                  }


                  })
          
          
          }else{
            layer.open({
                content: '最低金额为1元！'
                ,skin: 'msg'
                ,time: 2//2秒后自动关闭
              });
          }
            
          })

        });

        $('.set_pack_return').click(function(){
          location.reload();
          $('.set_pack_next').css('display','none');
        });

      $('.pack-red').click(function(){
        var _this = $(this).prevAll('.red-bag');
        var inputV = _this.children('.master-red').children('input').val();
        var pV = _this.children('.apprentice-red').children('h4').html();
        var inputAttr = _this.children('.master-red').children('input').attr("attr");
        var tempAttr = _this.children('.master-red').children('input').attr("tacit");
   
        if(inputV){
          if(parseInt(inputV) == tempAttr){
            layer.open({
                content: '您未修改红包金额！'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
              });
            return;
          }
          if(parseInt(inputV) > inputAttr){
            layer.open({
                content: '最高只能输入'+inputAttr+'元！'
                ,skin: 'msg'
                ,time: 2.5 //2秒后自动关闭
              });
            return;
          }
        }else{
            layer.open({
                content: '请输入金额！'
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
              });
            return;
          }
      
          //包红包
          $.post('/Home/Circle/set_pack/platform_id/{$_GET[platform_id]}',postdata,function(res){
            if(res.err==0){
			    var temp_back = '<div>'
                layer.open({
                //content: '徒弟投资之后将收到'+inputV+'元红包，您可以获得'+pV+' 元红包'
                  content:'<div class="suc_back">'+
                  '<img src="__PUBLIC__images/set_back@1.png">'+
                  '<p>徒弟投资之后将收到'+inputV+'元红包，</p>'+
                  '<p>您可以获得'+pV+'元红包</p>'+
                '</div>'
                ,btn: ['确认分享该投资红包', '继续设置红包']
                ,yes: function(index){
                  location.href="/Home/Recommend/m_marketing/recommend_id/{$_SESSION['user']['id']}/p_id/{$_GET['platform_id']}/s/"+scheme_id
                },no: function(index){
                  location.reload();
                  layer.close(index);
                }
              });
            }else{
        layer.open({
                  content: res.msg
                  ,skin: 'msg'
                  ,time: 2 //2秒后自动关闭
                });
      }
          })

      });
      </script>
</block>